/**
 * @file PhotoLoader.as
 *  
 照片下载
 *  
 addChild(new PhotoLoader(url,ww,hh,defaultbmp,txt_str));

 * @author db0@qq.com
 * @version 1.0.1
 * @date 2014-07-04
 */
package 
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.display.BitmapData;
	import flash.events.Event;
	import flash.text.TextField;
	/*import flash.text.TextFormat;*/

	public class PhotoLoader extends Sprite 
	{
		public var obj:Object;//照片对应的人物对象
		private var ww:int;//区域宽
		private var hh:int;//区域高
		private var defaultbmp:Bitmap;//默认的填充图像
		private var fullFill:Boolean;//默认的填充图像
		private var str:String;//照片底下的文本
		public function PhotoLoader(url:String,_width:int=0,_height:int=0,fullFill:Boolean=false,_defaultbmp:Bitmap=null){
			mouseChildren = false;
			ww = _width;
			hh = _height;
			defaultbmp = _defaultbmp;
			this.fullFill = fullFill;
			ViewSet.removes(this);
			if (ww > 0 && hh > 0){
				var bg:Bitmap = new Bitmap(new BitmapData(ww, hh));
				addChild(bg).alpha = 0;//照片的显示区域,

			}
			SwfLoader.SwfLoad(url,loaded);
		}
		public var bmp:Bitmap;
		private function loaded(e:Event=null):void
		{
			//visible = true;
			if(e && e.type == Event.COMPLETE)
			{
				bmp = e.target.content as Bitmap;
				if (ww > 0 && hh > 0){
					if (fullFill){
						ViewSet.fullRect(bmp,this, 0, 0, ww, hh);
					}else{
						ViewSet.fullCenter(bmp, 0, 0, ww, hh);
					}
				}else if(ww<0 || hh<0) {
					var w:int = Math.abs(ww);
					var h:int = w*.75;
					ViewSet.fullCenter(bmp,0,0,w,h);
					bmp.smoothing = true;
					bmp.x = - bmp.width/2;
					bmp.y = - bmp.height/2;
				}else{
					w = 300;
					h = w*.75;
					graphics.clear();
					graphics.lineStyle(2, 0xffffff);
					graphics.beginFill(0x0,1.0);
					graphics.drawRect( -w / 2-2, -h / 2-2, w+4, h+4);
					graphics.endFill();

					ViewSet.fullCenter(bmp,0,0,w,h);
					bmp.x = - bmp.width/2;
					bmp.y = - bmp.height/2;
				}
				addChild(bmp);
			}else if(defaultbmp){
				bmp = new Bitmap(defaultbmp.bitmapData);
				ViewSet.fullCenter(bmp,0,0,ww,hh);
				addChild(bmp);
			}else{
				logs.adds("no photo");
				visible = false;
			}
		}
	}
}

